# -*- coding: utf-8 -*-

import cv2 as cv
import numpy as np

img = cv.imread("photos/dog.jpg")
cv.imshow("dog", img)

# # 图像平移
# # Translation
# def translate(img, x, y):
#     # 平移矩阵
#     # 1,0,x
#     # 0,1,y
#     # 0,0,1
#     transMat = np.float32([[1,0,x], [0,1,y]])
#     dimensions = (img.shape[1], img.shape[0])
    
#     # 仿射变换的功能是从二维坐标到二维坐标之间的线性变换，且保持二维图形的“平直性”和“平行性”。
#     # 仿射变换可以实现，包括平移，缩放，翻转，旋转和剪切
#     return cv.warpAffine(img, transMat, dimensions)

# # -x ==> left 
# # -y ==> up
# #  x ==> right
# #  y ==> down
# translated = translate(img, 100, 100)
# cv.imshow("Translated", translated)


# # 图像旋转
# # Rotation
# def rotate(img, angle, rotPoint=None):
#     (height, width) = img.shape[:2]
    
#     if rotPoint is None:
#         rotPoint = (width//2, height//2)
    
#     # 旋转矩阵
#     # cos@,-sin@,0
#     # sin@,cos@,0
#     # 0,0,1
#     rotMat = cv.getRotationMatrix2D(rotPoint, angle, 1.0)
#     dimensions = (width, height)
    
#     return cv.warpAffine(img, rotMat, dimensions)

# # angle 顺时针角度
# # -angle 逆时针角度
# rotated = rotate(img, 45)
# cv.imshow("Rotated", rotated)



# 图像翻转
# Flipping

# =0 垂直翻转
# >0 水平翻转
# <0 垂直水平翻转
flip = cv.flip(img, 0)
cv.imshow(f"vertical flip", flip)

flip = cv.flip(img, 1)
cv.imshow(f"horizontal flip", flip)

flip = cv.flip(img, -1)
cv.imshow(u"vertical horizontal flip", flip)

cv.waitKey(0)